//
//  BYAddressController.m
//  OCDemo
//
//  Created by zhumuzhi on 2022/2/17.
//

#import "BYAddressController.h"
#import "BYConfirmOrderAddressCell.h"

#import "BYAddNewAddressController.h"

@interface BYAddressController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) NSMutableArray    *dataList;
@property (nonatomic, strong) BYTableView       *tableView;
@property (nonatomic, strong) UIButton          *addNewAddress;

@end

@implementation BYAddressController

NSString *kBYAddressCellID = @"kBYAddressCellId";

#pragma mark - Event
- (void)addNewAddressEvent {
    BYAddNewAddressController *controller = [[BYAddNewAddressController alloc] init];
    [self.navigationController pushViewController:controller animated:YES];
}

#pragma mark - LifeCycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.addNewAddress];
    
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1 ;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BYConfirmOrderAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:kBYAddressCellID];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44.0f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"选中传递，退出，传递给确认订单");
}


#pragma mark - LaztGet

- (NSMutableArray *)dataList {
    if (!_dataList) {
        _dataList = [NSMutableArray array];
    }
    return _dataList;
}

- (BYTableView *)tableView {
    if (!_tableView) {
        _tableView = [[BYTableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-kSafeAreaTopHeight-kSafeAreaBottomHeight-kAutoWithSize(110)) style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.backgroundColor = BACKGROUND_VIEW_COLOR;
        [_tableView registerClass:[BYConfirmOrderAddressCell class] forCellReuseIdentifier:kBYAddressCellID];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

- (UIButton *)addNewAddress {
    if (!_addNewAddress) {
        _addNewAddress = [[UIButton alloc] initWithFrame:CGRectMake(kAutoWithSize(10), kScreenHeight-kSafeAreaTopHeight-kSafeAreaBottomHeight-kAutoWithSize(100)-kAutoWithSize(5), kScreenWidth-kAutoWithSize(20), kAutoWithSize(50))];
        [_addNewAddress setTitle:@"添加新地址" forState:UIControlStateNormal];
        [_addNewAddress setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
        [_addNewAddress setBackgroundColor:PUBLIC_ORANGE_COLOR forState:UIControlStateNormal];
        [_addNewAddress setBackgroundColor:PUBLIC_ORANGE_COLOR forState:UIControlStateSelected];
        [_addNewAddress setViewCornerRadius:kAutoWithSize(8)];
        [_addNewAddress addTarget:self action:@selector(addNewAddressEvent) forControlEvents:UIControlEventTouchUpInside];
    }
    return _addNewAddress;
}


@end
